﻿using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing.Design;
using System.Security.Permissions;
using JsonEditor.Common;

namespace JsonEditor.Models
{
    [PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
    public class JsonNode
    {
        /// <summary>
        /// 键
        /// </summary>
        [ReadOnly(false)]//是否只读
        [Browsable(true)]//是否在窗口显示
        [Category("Json属性")]//对参数进行分组
        [DisplayName("JsonKey")]//设置参数显示名称
        [Description("Json键名称，Key")]//参数描述
        public string Key
        {
            get;
            set;
        }
        /// <summary>
        /// 键值
        /// </summary>
        [ReadOnly(false)]//是否只读
        [Browsable(true)]//是否在窗口显示
        [Category("Json属性")]//对参数进行分组
        [DisplayName("JsonKeyValue")]//设置参数显示名称
        [Description("键值，Key对应的值")]//参数描述
        //[Editor(typeof(PopupEditor), typeof(UITypeEditor))]
        public object Value
        {
            get;
            set;
        }
    }
    [PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
    public class JsonNode<T> : UITypeEditor where T : class
    {
        //[DefaultValue(false)]//默认值
        /// <summary>
        /// 键
        /// </summary>
        [ReadOnly(false)]//是否只读
        [Browsable(true)]//是否在窗口显示
        [Category("Json属性")]//对参数进行分组
        [DisplayName("JsonKey")]//设置参数显示名称
        [Description("Json键名称，Key")]//参数描述
        public string Key
        {
            get;
            set;
        }
        /// <summary>
        /// 键值
        /// </summary>
        [ReadOnly(false)]//是否只读
        [Browsable(true)]//是否在窗口显示
        [Category("Json属性")]//对参数进行分组
        [DisplayName("JsonKeyValue")]//设置参数显示名称
        [Description("键值，Key对应的值")]//参数描述
        //[Editor(typeof(PopupEditor), typeof(UITypeEditor))]
        //[Editor("System.Windows.Forms.Design.ListControlStringCollectionEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
        [Editor("System.Windows.Forms.Design.StringCollectionEditor, System.Design", "System.Drawing.Design.UITypeEditor, System.Drawing")]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        [MergableProperty(false)]
        public T Value
        {
            get;
            set;
        }

        public bool Save()
        {
            try
            {
                var d = this;
                return true;
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
    }
}
